package com.example.haoqisystem.controller;

import com.example.haoqisystem.entity.ApplicationCompany;
import com.example.haoqisystem.request.CreateApplicationCompanyRequest;
import com.example.haoqisystem.request.UpdateApplicationCompanyRequest;
import com.example.haoqisystem.response.BaseResponse;
import com.example.haoqisystem.service.ApplicationCompanyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "申请公司")
@RestController
@RequestMapping("/applicationCompany")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class ApplicationCompanyController {

    private final ApplicationCompanyService applicationCompanyService;

    @ApiOperation(value ="注册申请公司")
    @PostMapping("/register")
    public BaseResponse<ApplicationCompany> register(@RequestBody CreateApplicationCompanyRequest request){
        return applicationCompanyService.register(request);
    }

    @ApiOperation(value = "登录")
    @GetMapping("/login")
    public BaseResponse<ApplicationCompany> login(@RequestParam("account") String account
            ,@RequestParam("password") String password){
        return applicationCompanyService.login(account,password);
    }

    @ApiOperation(value = "更新信息")
    @PutMapping("/update")
    public BaseResponse<ApplicationCompany> update(@RequestBody UpdateApplicationCompanyRequest request){
        return applicationCompanyService.update(request);
    }

    @ApiOperation(value = "列表查询")
    @GetMapping("/queryList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "companyName",value = "公司名（模糊查询)"),
            @ApiImplicitParam(name = "id",value = "id",dataType = "Long")
    })
    public BaseResponse<List<ApplicationCompany>> queryList(String companyName,Long id){
        return applicationCompanyService.queryList(companyName,id);
    }

    @ApiOperation(value = "删除公司")
    @GetMapping("/delete")
    public BaseResponse<String> delete(@RequestParam("id") Long id){
        return applicationCompanyService.delete(id);
    }
}
